﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

namespace HandLab.WebApp.RadControls
{
    public partial class ContextMenu : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void RadTreeView1_ContextMenuItemClick(object sender, RadTreeViewContextMenuEventArgs e)
        {
            // get the collection that holds the node who owns the menu
            RadTreeNodeCollection collection = e.Node.ParentNode.Nodes;
            // get the index of the node
            int curIndex = e.Node.Index;

            switch (e.MenuItem.Text)
            {
                case "Move up":
                    if (curIndex > 0) // only move up if not at top
                    {
                        // remove the node and insert in new position
                        collection.Remove(e.Node);
                        collection.Insert(curIndex - 1, e.Node);
                    }
                    break;
                case "Move down":
                    if (curIndex < collection.Count - 1) // only move down if not at end
                    {
                        // remove the node and insert in new position
                        collection.Remove(e.Node);
                        collection.Insert(curIndex + 1, e.Node);
                    }
                    break;
                case "Delete":
                    // remove the node
                    collection.RemoveAt(curIndex);
                    break;
            }
        }
    }
}